#include <REGX52.H>
#include "OneWire.h"

//define这里不能以;结尾
#define DS18B20_SKIP_ROM 0xCC
#define DS18B20_CONVERT_T 0x44
#define DS18B20_READ_T 0xBE

void DS18B20_ConvertT(){
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);
	OneWire_SendByte(DS18B20_CONVERT_T);
}

float DS18B20_ReadT() {
	unsigned char TL, TM;
	int Temp;
	float T;
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);
	OneWire_SendByte(DS18B20_READ_T);
	TL = OneWire_ReceiveByte();
	TM = OneWire_ReceiveByte();
	
	Temp = (TM<<8) | TL; //高8位和低8位合并
	
	T = Temp/16.0; //硬件中的数据扩大了16倍
	return T;
}